package com.test.link;

public class OddEvenList {
    public static  ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode odd = head, even = head.next, evenHead = even;
        while (even != null && even.next != null) {
            odd.next = odd.next.next;
            odd = odd.next;
            even.next = even.next.next;
            even = even.next;
        }
        odd.next = evenHead;
        return head;
    }
    public static void main(String[] args) {
        ListNode newNode = new ListNode(1);
        newNode.next=new ListNode(2);
        newNode.next.next=new ListNode(3);
        newNode.next.next.next=new ListNode(4);
        newNode.next.next.next.next=new ListNode(5);
        ListNode listNode = oddEvenList(newNode);
        while (listNode!=null){
            System.out.println(listNode.val);
            listNode = listNode.next;
        }
    }
}
